<?php
namespace app\serverintegralmall\logic;
use \app\manage\logic\BaseLogic;
use \app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-11-02 14:50:07
 * @Description: 积分商品订单
 */

class Order extends BaseLogic{
	
   
    protected $orderLogic = '\app\serverintegralmall\logic\Order';
    protected $orderValidate = '\app\serverintegralmall\validate\Order';

    /*后台对某积分订单进行发货操作*/
    public function shipmentsGoods($data): array 
    {
        $request = \Think\Request::instance();
        //获取基本信息 + 订单详情
        $service = new ApiBase($data['token']);
        $app_key = \app\manage\service\ApiBase::getAppKey();
        $getBase['query'] = json_encode([
            ['path'=>'serveruser/auth/Token/hGetAll', 'param'=>['token'=>$data['token']]],
            ['path'=>'serveruser/auth/App/find', 'param'=>['app_key'=>$app_key]],
            ['path'=>'serverintegralmall/order/Order/adminIntegralOrderInfo', 'param'=>['id'=>$data['id']]]
        ]);
        $baseInfo = $service->sendDataLots(config('proxy_all_url'), $getBase);
        if($baseInfo['status'] != SUCCESS_STATUS){
            return $baseInfo;
        }
        //获取用户信息
        $getUserInfo['query'] = json_encode([
            ['path'=>'serveruser/user/User/info', 'param'=>['id'=>$baseInfo['res'][2]['user_id']]]
        ]);
        $userInfo = $service->sendDataOne(config('proxy_all_url'), $getUserInfo);
        if($userInfo['status'] != SUCCESS_STATUS){
            return $userInfo;
        }

        //解冻用户积分 + 用户积分转账平台积分 + 进行发货操作
        $unfreeze['user_id'] = $transfer['user_id'] = $baseInfo['res'][2]['user_id'];
        $unfreeze['opposite_id'] = $transfer['opposite_id'] = $baseInfo['res'][0]['id'];
        $unfreeze['integral'] = $transfer['integral'] = bcmul($baseInfo['res'][2]['integral'], $baseInfo['res'][2]['number']);
        $unfreeze['update_ip'] = $transfer['update_ip'] = $request->ip();
        $unfreeze['app_id'] = $transfer['app_id'] = $baseInfo['res'][1]['id'];
        $unfreeze['type'] = 'integral_order';
        $unfreeze['obj_id'] = $baseInfo['res'][2]['id'];
        $unfreeze['freeze_counts'] = 1;
        $unfreeze['user_info'] = $transfer['user_info'] = $userInfo['res'];
        $unfreeze['opposite_info'] = $transfer['opposite_info'] = $baseInfo['res'][0];
        $shipmentsGoods['id'] = $baseInfo['res'][2]['id'];
        $shipmentsGoods['logistics_company_code'] = $data['logistics_company_code'];
        $shipmentsGoods['logistics_company_name'] = $data['logistics_company_name'];
        $shipmentsGoods['waybill_number'] = $data['waybill_number'];
        $queryOne['query'] = json_encode([
            ['path'=>'serverfund/integral/IntegralAccount/unfreeze', 'param'=>$unfreeze],
            ['path'=>'serverfund/integral/IntegralAccount/transfer', 'param'=>$transfer],
            ['path'=>'serverintegralmall/order/Order/shipmentsGoods', 'param'=>$shipmentsGoods]
        ]);
        return ApiBase::sendDataLots(config('proxy_queue_url'), $queryOne);
    }
    

}